﻿<?php
session_start();
require('conn.php');
require('functions.php');
//全站访问
if($config['fangwen']==4){
	exit('网站正在更新');
}
$refer=$_GET['refer'];	
$ip=GetIP();
$day=date("Y-m-d",time());
$time=date("Y-m-d H:i",time());

// var_dump($_COOKIE['login']);
if ($_COOKIE['login']==1) {

	$c_phone=$_COOKIE['_phone'];
	$c_password=md5($_COOKIE['_password']);
		$row=$mysql->query("select * from `userdata` where `phone`='{$c_phone}' and `pass`='{$c_password}' limit 1");
	if($row){
		//登录赠送金额
		$row_login_ip=$mysql->query("select * from `refererdata` where `uid`='{$row[0]['id']}' and `aid`='0' and `day`='{$day}' limit 1");
		if(!$row_login_ip){
			$mysql->query("insert into `refererdata` values(null,'{$row[0]['id']}','0','ID：{$row[0]['id']}用户登录','','{$config['daysong']}','','','{$ip}','{$day}','{$time}')");
			//加钱
			$mysql->query("update `userdata` set `money`=`money`+'{$config['daysong']}',`money_all`=`money_all`+'{$config['daysong']}' where `id` in({$row[0]['id']}) limit 1");					
		}
		//保存账号密码，保存一天
		if($save==1){
			setcookie('_phone',$phone,time()+3600*24*365);
			setcookie('_password',$password,time()+3600*24*365);
		}
		
		setcookie('login',1,time()+3600*24*365);
		$_SESSION['userdata']=$row[0];
		$_SESSION['login']=1;
		if (isset($refer)) {
		_location("{$site}/{$refer}",301);
		}else{
		_location("{$site}/ucenter.php",301);
			
		}
		exit;
		//如果有链接 就跳转到链接
	}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title>登录 | <?php echo $config['sitename']?></title>
<meta name="keywords" content="<?php echo $config['sitename']?>,登录" />
<meta name="description" content="<?php echo $config['sitename']?>用户登录。">
<script type="text/javascript" src="<?php echo $site?>/static/jquery.js"></script>
<link href="<?php echo $site?>/static/all.css" type="text/css" rel="stylesheet" media="all">
<style>
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { 
    color:    #6b6b6b;
}
input:-moz-placeholder, textarea:-moz-placeholder { 
    color:    #6b6b6b;
}
input::-moz-placeholder, textarea::-moz-placeholder { 
    color:    #6b6b6b;
}
input:-ms-input-placeholder, textarea:-ms-input-placeholder { 
    color:    #6b6b6b;
}
body{margin:0;}
*{box-sizing:border-box;}
input{font-size: 16px;line-height: 1.25em;outline: 0px none;text-decoration: none;margin:0;}
.bg{background: url('static/images/bg.png') center center;-webkit-background-size: 100px 100px;background-size: 100px 100px;-moz-background-size: 100px 100px;}
.input-icon-1,.input-icon-2{ float: left;width: 25px;border-bottom: 1px solid #6b6b6b;padding-bottom: 10px;padding-bottom: 7px;padding-top: 8px;}
</style>

</head>

<body class="bg">

<div class="common-wrapper" style="background:transparent">
	<div class="main" style="margin-top: 12%;">
	<div align="center">
		<img class="logo-big" src="static/images/logo.png" style="width:40%" alt="logo">
	</div>
	<?php 
			if(isset($refer)) {
				echo '<form action="login.php?refer='.$refer.'"method="post">';
			}else{
				echo'<form action="login.php" method="post">';
			}
	?>
			<div class="item clearfix"  style="width:90%;margin-left:5%;margin-top: 1em;">
				<img class="input-icon-1" src="static/images/phone_logo.png">
				<input style="background: transparent;color:#6b6b6b;float: left;width:90%;border-color: #6b6b6b;font-family: Arial" value="<?php echo $_COOKIE['_phone']?>" class="txt-input txtpd" name="phone"  placeholder="请输入已验证手机号" type="text" />
			</div>
			<div class="item clearfix" style="width:90%;margin-left:5%">
				<img class="input-icon-2" src="static/images/pw_logo.png">
				<input style="background: transparent;color:#6b6b6b; float: left;width:90%;border-color: #6b6b6b;" value="<?php echo $_COOKIE['_password']?>"  name="password" class="txt-input txtpd" placeholder="请输入密码" type="password" />
			</div>
			<div style="margin-bottom: 5px;padding-top: 5px;color:#6b6b6b;width:90%;margin-left:5%" class="item item-login-option clearfix">
				<div class="item"  style="float:left;width:50%"><input name="save" type="checkbox" value="1" checked="checked" />保存账号密码</div>
				<div class="item" style="float:left;width:50%;text-align: right;" ><a style="font-size:15px;color:#6b6b6b" href="<?php echo $site?>/find.php">找回密码</a></div>
			</div>
			<div class="item item-btns" style="width:90%;margin-left:5%"> 
			<input style="background: #9a0000;line-height: 25px;border-radius: 4px;" type="submit" value="登录" class="btn-login">
			</div>			
		</form>
		<div style="margin-top: 1em;width:90%;margin-left:5%"  class="item">
		<span><a style="color: #6b6b6b;border: 1px solid #6b6b6b;background: rgba(255,255,255,0.4);line-height: 40px;border-radius: 4px;" href="reg.php" class="btn-login">注册一个新帐号</a></span>
		</div>

	</div>
</div>
<?php
//登录验证
if($_POST){
	$phone=guolv(trim($_POST['phone']));
	$md5password=md5(($_POST['password']));
	$password=($_POST['password']);
	$save=guolv(trim($_POST['save']));
	$refer=$_GET['refer'];
	//$code=guolv(trim($_POST['code']));
	if(is_phone($phone)==false){
		echo "<script>alert('请输入正确的手机号');</script>";
		exit;
	}
	if($password==''){
		echo "<script>alert('请输入密码');</script>";
		exit;		
	}	
	$row=$mysql->query("select * from `userdata` where `phone`='{$phone}' and `pass`='{$md5password}' limit 1");
	if($row){
		//登录赠送金额
		$row_login_ip=$mysql->query("select * from `refererdata` where `uid`='{$row[0]['id']}' and `aid`='0' and `day`='{$day}' limit 1");
		if(!$row_login_ip){
			$mysql->query("insert into `refererdata` values(null,'{$row[0]['id']}','0','ID：{$row[0]['id']}用户登录','','{$config['daysong']}','','','{$ip}','{$day}','{$time}')");
			//加钱
			$mysql->query("update `userdata` set `money`=`money`+'{$config['daysong']}',`money_all`=`money_all`+'{$config['daysong']}' where `id` in({$row[0]['id']}) limit 1");					
		}
		//保存账号密码，保存一天
		if($save==1){
			setcookie('_phone',$phone,time()+3600*24*365);
			setcookie('_password',$password,time()+3600*24*365);
		}
		
		setcookie('login',1,time()+3600*24*365);
		$_SESSION['userdata']=$row[0];
		$_SESSION['login']=1;
		if (isset($refer)) {
		_location("{$site}/mission/index.php",301);
		}else{
		_location("{$site}/ucenter.php",301);
			
		}
		exit;
		//如果有链接 就跳转到链接
	}else{
		echo "<script>alert('用户名或密码错误');</script>";
		exit;
	}
}
$mysql->__destruct();
$mysql->close();
?>

</body>
</html>